package com.hdw.auth.service;

import com.hdw.common.vo.PaginationVO;
import org.springframework.stereotype.Service;
import com.hdw.auth.api.BaseAuthUseService;
import com.hdw.auth.mapper.BaseAuthUseMapper;
import com.hdw.auth.bean.model.BaseAuthUse;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * baseAuthUse服务实现类
 * Created by liujunlei on 2022/01/05.
 */
@Service
@Transactional
public class BaseAuthUseServiceImpl implements BaseAuthUseService{

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseAuthUseServiceImpl.class);

    @Autowired
    private BaseAuthUseMapper baseAuthUseMapper;

    @Override
    public int insert(BaseAuthUse baseAuthUse) {
        return baseAuthUseMapper.insert(baseAuthUse);
    }

    @Override
    public int insertSelective(BaseAuthUse baseAuthUse)  {
        return baseAuthUseMapper.insertSelective(baseAuthUse);
    }

    @Override
    public int deleteById(Long idUse)  {
        return baseAuthUseMapper.deleteByPrimaryKey(idUse);
    }

    @Override
    public int updateByIdSelective(BaseAuthUse baseAuthUse)  {

        return baseAuthUseMapper.updateByPrimaryKeySelective(baseAuthUse);
    }

    @Override
    public int updateById(BaseAuthUse baseAuthUse)  {
        return baseAuthUseMapper.updateByPrimaryKey(baseAuthUse);
    }

    @Override
    public BaseAuthUse getById(Long idUse)  {
        return baseAuthUseMapper.selectByPrimaryKey(idUse);
    }

    @Override
    public List<BaseAuthUse> findByModel(BaseAuthUse baseAuthUse)  {
        return baseAuthUseMapper.findByModel(baseAuthUse);
    }

    @Override
    public PaginationVO<BaseAuthUse> findPageByModel(BaseAuthUse baseAuthUse, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<BaseAuthUse> quesList = baseAuthUseMapper.findByModel(baseAuthUse);
        PageInfo<BaseAuthUse> pageInfo = new PageInfo<>(quesList);
        PaginationVO<BaseAuthUse> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public BaseAuthUse getByCd(String cd) {
        BaseAuthUse use = new BaseAuthUse();
        use.setCd(cd);
        use.setFgAct(true);
        List<BaseAuthUse> list = this.findByModel(use);
        return list.size()>0?list.get(0):null;
    }
}
